#!/bin/bash
###
 # @Author: admin@attacker.club
 # @Date: 2022-10-21 14:23:27
 # @LastEditTime: 2022-10-21 16:40:05
 # @Description: 
### 

#npm install
npm run build

image_tag=dev-$(date +"%Y-%m-%d-%H%M");
echo "new tag: "$image_tag;

docker build -f Dockerfile -t harbor.opsbase.cn/public/demo-devops-web:$image_tag .
docker push harbor.opsbase.cn/public/demo-devops-web:$image_tag
docker build -f Dockerfile -t harbor.opsbase.cn/public/demo-devops-web:test --build-arg API_PROXY="www.baidu.com" .

## 重新部署
curl -X PUT \
    -H "content-type: application/json" \
    -H "Cookie: KuboardUsername=admin; KuboardAccessKey=bskzh742bdpyxxx" \
    -d '{"kind":"deployments","namespace":"demo","name":"devops-web-layout-svc","images":{"harbor.opsbase.cn/public/demo-devops-web":"harbor.opsbase.cn/public/demo-devops-web:yourNewVersion"}}' \
    "http://kuboard.pod.opsbase.cn/kuboard-api/cluster/default/kind/CICDApi/admin/resource/updateImageTag"


## 重启
curl -X PUT \
    -H "Content-Type: application/yaml" \
    -H "Cookie: KuboardUsername=admin; KuboardAccessKey=xxxxx" \
    -d '{"kind":"deployments","namespace":"demo","name":"devops-web-layout-svc"}' \
    "http://kuboard.pod.opsbase.cn/kuboard-api/cluster/default/kind/CICDApi/admin/resource/restartWorkload"